package fr.epsi.fragment.pickers;

import android.app.Activity;
import android.app.Dialog;
import android.support.v4.app.DialogFragment;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TimePicker;

import java.util.Calendar;

/**
 * Created by Florent Baudon on 22/05/2014.
 */
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {

    ValidTimeSetListener listener;

    public void onAttach(Activity activity){
        super.onAttach(activity);
        try {
            listener = (ValidTimeSetListener) activity;
        }catch (ClassCastException e){
            e.printStackTrace();
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        //Heure actuel
        Calendar c = Calendar.getInstance();
        int heure = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        TimePickerDialog tpd = new TimePickerDialog(getActivity(), this, heure, minute, true);

        return tpd;
    }

    @Override
    public void onTimeSet(android.widget.TimePicker timePicker, int heure, int min) {
        listener.ValidTimeSet(this, heure, min);
    }

    public interface ValidTimeSetListener{
        public void ValidTimeSet(DialogFragment fragment, int heure, int min);
    }
}